    function user(){
        var login = document.querySelector('.login');
        console.log(login);
        var id = localStorage.getItem('id')
        var token = localStorage.getItem('token')
        // 首页不登录也是可以访问的，所以获取id和token，登录就才会有，不登录就没有
        // 对id和token做判断，有就显示，没有就不显示
        console.log(id,token);
    
        if(id && token){
            document.querySelector('.list').setAttribute('href',"list.html?token="+token+'&id='+id)
            document.querySelector('.cart').setAttribute('href',"cart.html?token="+token+'&id='+id)
            document.querySelector('#shouye').setAttribute('href',"home.html?token="+token+'&id='+id)
            document.querySelector('#liebiao').setAttribute('href',"list.html?token="+token+'&id='+id)
            // 发送ajax获取用户信息
            var xhr = new XMLHttpRequest;
            xhr.open('get',`http://localhost:8888/users/info/${id}`)
            xhr.setRequestHeader('authorization',token)
            xhr.send()
            xhr.onreadystatechange = function(){
                if(xhr.readyState === 4){
                    if(xhr.status>=200 && xhr.status<300){
                        var res = xhr.responseText;
                        res = JSON.parse(res)
                        console.log(res);
                        var {code} = res;
                        // console.log(res);
                        if(code === 1){
                            login.innerHTML = `
                            <a href="userinfo.html" class="user">登录成功</a>
                            <a data-id="${id}" data-token="${token}" href="javascript:;" class="logout">退出</a>
                            `
                        }
                        
                    }
                }
            }
        }
        login.onclick = function(){
            var target = window.event.target || window.event.srcElement;
            if(target.className === 'logout'){
                var xhr = new XMLHttpRequest;
                xhr.open('get','http://localhost:8888/users/logout/'+target.getAttribute('data-id'))
                xhr.setRequestHeader('authorization',target.getAttribute('token'))
                xhr.send()
                xhr.onreadystatechange = function(){
                    if(xhr.readyState === 4){
                        if(xhr.status>=200 && xhr.status<300){
                            var res = xhr.responseText;
                            res = JSON.parse(res)
                            console.log(res);
                            localStorage.removeItem('id');
                            var {code, message} = res;
                            if(code === 1){
                                alert(message)
                                // 将内容换成登录注册
                                location.href = "home.html"
                            }
                        }
                    }
                }
            }
        }
    
    }
    
